/**
  * Author: Mei
  * Date: 2020-11-20 17:07
  * Description: 
  *
  */
#include <iostream>
#include <vector>
#include <algorithm>
#include <memory>
#include <utility>
#include <functional>

using namespace std;

//类似于函数指针 作为返回值
function<int(void)> multiply(int x) {
    return [&x] { return 2 * x; };
}

//lambda作为参数
void testCallback(const vector<int> &vec, const function<bool(int)> &callback) {
    for (const auto &i : vec) {
        if (!callback(i)) {
            break;
        }
        cout << i << " ";
    }
    cout << endl;
}

int main() {
    //auto fn = multiply(2);
    //cout << fn() << endl;

    vector<int> vec{1, 2, 4, 5, 6, 42, 22,};
    testCallback(vec, [](int i) { return i < 6; });

    return 0;
}